FRP=0
FREEP='1'
store space(25) to suppcod,suppnam
set colo to bg+/b,w+/n
@  7, 1 CLEA TO 23,78
@  7, 3 TO 9,29
@  8, 5 SAY "PREPARE PURCHASE ORDERS"

PIL1=0
DO BOX2 WITH 12,3,"IS IT NEW PO #. ? :","YES","NO",'GR+','RB','GR+','R',PIL1,.F.,.T.
IF PIL1=1
   set colo to bg+/b,w+/n
   COMPCOD = SPACE(4)
   F1='SUPPLIER'
   set colo to bg+/b,w+/n
   @ 7,1 clear to 23,78
   CNT=0
   KODE=SPACE(4)
   kunci=space(5)
   do boxe with 11,3,'Enter Initial of Supplier Name : ','KUNCI','N','BG','W+','N',5,.T.,.T.
   if lastkey()=27
      set colo to bg+/b,w+/n
      return
   endif
   CNT=0
   do getsupp
   if lastkey()=27 .OR. CNT=0
      return
   endif
   SELE 1
   USE &DR&F1 INDE &DR&F1
   SEEK suppnam
   IF .NOT. EOF()
      IF REC_LOCK(0)
         REPL ORDR_N_Y_P WITH .T.
         REPL AEA_COMP WITH FREEP
      ENDIF
      UNLOCK
   ENDIF
   set colo to bg+/b,w+/n
   @ 11,3 CLEAR TO 23,78
   DO BOXT WITH 7,3,'SUPPLIER NAME : '+alltrim(SUPPNAM)+' ('+SUPPCOD+')','BG+','GR',.F.,.T.
   F1='PUR_DRUG'
   F2='PUR_DISP'
   SET EXCLU OFF
   USE &DR&F1
   GO BOTT
   PRNUM=ORDER_NBER
   SET EXCLU OFF
   USE &DR&F2
   GO BOTT
   PRNUM1=ORDER_NBER
   PRNUM=MAX(PRNUM,PRNUM1)
   PRNUM=PRNUM+1
   SET EXCLU OFF
   DO BOXT WITH 7,61,'PO #. : '+STR(PRNUM,5),'BG+','GR',.F.,.T.
ELSE
   set colo to bg+/b,w+/n
   COMPCOD = SPACE(4)
   F3='SUPPLIER'
   F1='PUR_DRUG'
   F2='PUR_DISP'
   set colo to bg+/b,w+/n
   @ 7,1 clear to 23,78
   PRNUM=0
   SET EXCLU OFF
   do boxn with 7,61,'PO #. :','prnum','99999','gr+','r','W+','N','999999','0',.f.,.t.
   SELE 1
   USE &DR&F1 INDE &DR&F1
   SEEK PRNUM
   IF EOF()
      SELE 2
      USE &DR&F2 INDE &DR&F2
      SEEK PRNUM
      IF EOF()
         DO BOXT WITH 20,51,'PO. #. NOT FOUND','GR+*','R',.T.,.T.
         PL9=0
         WAIT''
         RETURN
      ELSE
         IF ORDR_PRINT
            DO BOXT WITH 20,51,'PO. IS ALREADY PRINTED','GR+*','R',.T.,.T.
            PL9=0
            WAIT''
            RETURN
         ENDIF
      ENDIF
   ELSE
      IF ORDR_PRINT
         DO BOXT WITH 20,51,'PO. IS ALREADY PRINTED','GR+*','R',.T.,.T.
         PL9=0
         WAIT''
         RETURN
      ENDIF
   ENDIF

*   do boxn with 8,61,'PO #. :','prnum','99999','gr+','r','W+','N','999999','0',.f.,.t.
   SET COLO TO BG+/B,W+/N
   DO BOXT WITH 7,61,'PO #. : '+STR(PRNUM,5),'BG+','GR',.F.,.T.
   SUPPNAM=SUPP_NAME
   SUPPCOD=SUPP_CODE
   SELE 3
   USE &DR&F3 INDE &DR&F3
   SEEK suppnam
   SET COLOR TO BG/B
   @ 8,1 CLEAR TO 23,55
   IF EOF()
      RETURN
   ELSE
      DO BOXT WITH 7,3,'SUPPLIER NAME : '+alltrim(SUPPNAM)+' ('+SUPPCOD+')','BG+','GR',.F.,.T.
   ENDIF
ENDIF
   DO PUR_SP_A
